<template>
	<view class="manage">
		<view class="content">
			<view class="one">
				<block v-for="(item,index) of list" :key="index">
					<view class="container" v-if="item.state!=current">
						<view class="pic"><img :src="item.thumb" /></view>
						<view class="desc">
							<view class="title">
								<view class='title_l'>{{item.name}}</view>
							</view>
							<view class="price">¥ {{item.jiage}}</view>
							<view class="kc">
								<view></view>
								<view class="xiaol">成本价：{{item.chengben}}</view>
								<!-- <view class="xiaol">销量：{{item.xiaoliang}}</view> -->
							</view>
							<view class="chengban" @click="editFun(item.id)">编辑价格</view>
							<!-- <view class="btn">
								<view class="btn_01" @click="jump_edit(item.id)">查看推广记录</view>
							</view> -->
						</view>
					</view>
				</block>
			</view>
		</view>
		<button @click="to_tiaozhuan('../product/product')">添加商品</button>
		<view style="height:100rpx;"></view>
		<view class="trea-mask" @click="closebuy" v-if="kuang"></view>
		<view class="buy-trea" v-if="yudingpopup">
			<view class="text">编辑价格</view>
			<input type="text" @input="getInput" :value="infoInput" placeholder="请输入"/>
			<view class="enter margin_top_20" @click="enterFun()">保存</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				items: ['上架商品', '下架商品'],
				current: 0,
				kuang:false,
				yudingpopup:false,
				infoInput:'',
				id:''
			}
		},
		onLoad() {
			this._request()
		},
		methods: {
			to_tiaozhuan(url){
				uni.navigateTo({
					url:url
				})
			},
			_request() {
				this.global.request.post({
					data: {
						do: 'shangjia_manage',
						op:'my_goods'
					},
					success: res => {
						this.list = res
					}
				})
			},
			pull(id) {
				const that = this
				uni.showModal({
					title: '确定下架？',
					success(res) {
						if (res.confirm == true) { 
							that.$api.msg('下架成功')
							that._request() 
						}
					}
				})
			},
			del(id) {
				const that = this
				uni.showModal({
					title: '确定删除？',
					success(res) {
						if (res.confirm == true) {
							that.$api.msg('删除成功')
							that._request()
						}
					}
				})
			},
			push(id) {
				const that = this
				uni.showModal({
					title: '确定上架？',
					success(res) {
						if (res.confirm == true) {
							that._request()
						}
					}
				})
			},
			jump_edit(id) {
				uni.navigateTo({
					url: '/pagesA/fabu/tuiguang_log?types=goods_tg&id=' + id
				})
			},
			onClickItem(index) {
				if (this.current !== index) {
					this.current = index;
				}
			},
			editFun(id){
				this.id = id
				this.yudingpopup = true
				this.kuang = true
			},
			closebuy(){
				this.yudingpopup = false
				this.kuang = false
			},
			//保存
			enterFun(){
				this.global.request.post({
					data: {
						do: 'shangjia_manage',
						op:'edit_goods_chengben',
						g_id:this.id,
						chengben:this.infoInput
					},
					success: res => {
						this.closebuy()
					}
				})
			},
			getInput(e){
				this.infoInput = e.detail.value
			}
		}
	}
</script>

<style lang="scss">
	.manage {
		padding: 0 30rpx;
		.one {
			.container {
				display: flex;
				flex-direction: row;
				border-bottom: 1px solid #F2F2F2;
				justify-content: space-between;
				height: 260rpx;
				padding: 10rpx 0;
				margin: 0 0 20rpx;
				background: #fff;

				.pic {
					display: flex;
					flex-direction: column;
					justify-content: center;
					width: 25%;
					height: 100%;
					vertical-align: middle;
				}

				.pic img {
					width: 100%;
					height: 80%;
					border-radius: 10rpx;
				}

				.desc {
					color: #8B8B8B;
					width: 70%;
					padding: 20rpx;
					text-align: left;
					font-size: 12px;

					.title {
						display: flex;
						flex-wrap: wrap;
					}

					.title_l {
						font-weight: bold;
						color: #333;
						height: 36px;
						overflow: hidden;
						font-size: 14px;
						line-height: 18px;
					}

					.price {
						color: red;
						font-size: 16px;
						font-weight: 900;
					}

					.kc {
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						align-items: center;
						line-height: 50rpx;

						.xiaol {
							color: #8B8B8B;
						}
					}

					.btn {
						display: flex;
						justify-content: flex-end;

						.btn_01 {
							border: 1px solid #8B8B8B;
							border-radius: 3px;
							text-align: center;
							margin-left: 10px;
							padding: 3px 8px;
						}
					}
				}
			}

			.tjsp {
				padding: 0 10px;
				position: fixed;
				bottom: 0;
				left: 0;
				width: 100%;
				box-sizing: border-box;
				z-index: 99;
				background-color: #fff;

				.tjsp_btn {
					background-color: #E5E5E5;
					padding: 10px;
					text-align: center;
					border-radius: 20px;
					background-color: #DF421D;
					color: #fff;
					width: 100%;
				}
			}

		}
	}
	.chengban{
		width: 150rpx;
		color: #FFFFFF;
		background: $uni-themd;
		text-align: center;
		border-radius: 10rpx;
		padding: 4rpx 0;
		margin-left: 20rpx;
	}
	.buy-trea{
		position: fixed;
		top: 30%;
		left: 20%;
		width: 60%;
		padding: 30rpx;
		background: #fff;
		border-radius: 20rpx;
		z-index: 997;
		// transform: translate3d(0, 120%, 0);
		transition: all .3s cubic-bezier(.25, .5, .5, .9);
		display: flex;
		flex-direction: column;
		align-items: center;
		input{
			margin-top: 20rpx;
			height: 70rpx;
			background: #F1F1F1;
			text-align: center;
			border-radius: 10rpx;
		}
	}
	.trea-mask {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		background: rgba(0, 0, 0, .5);
		z-index: 994;
	}
	.enter{
		width: 200rpx;
		text-align: center;
		padding: 6upx 20upx;
		color: #fff;
		background-color: #F86620;
		border-radius: 40upx;
	}
	button {
		width: 92%;
		background-color: #FD7A4D;
		color: white;
		position: fixed;
		bottom: 0;
		margin-bottom: 20rpx;
	}
</style>
